package com.store.framework.rest;

import java.util.List;
import java.util.UUID;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.store.framework.entry.RootList;
import com.store.framework.logic.IAppRootListLogic;
import com.store.framework.logic.imp.AppRootListLogic;

public class ARootListService {
	private static Log LOG = LogFactory.getLog(ARootListService.class);

	IAppRootListLogic iarll = new AppRootListLogic();

	@POST
	@Path("AddRootList")
	@Produces("application/json; charset=UTF-8")
	public String AddRootList(RootList input) {
		LOG.debug(iarll);
		// Error
		// Info
		// Ware
		// Debug
		JSONObject js = JSONObject.fromObject(input);
		@SuppressWarnings("static-access")
		RootList rm = (RootList) js.toBean(js, RootList.class);
		rm.setId(UUID.randomUUID().toString());
		iarll.AddRootList(rm);
		return "{\"result\":1}";

	}

	@POST
	@Path("AddRootList")
	@Produces("application/json; charset=UTF-8")
	public String selectRootList() {
		@SuppressWarnings("rawtypes")
		List list = iarll.Select();
		JSONArray ja = JSONArray.fromObject(list);
		LOG.debug(ja);
		return ja.toString();

	}

	public static void main(String[] args) {
		new ARootListService().selectRootList();
	}
}
